{% extends  'templates/base.html' %}

{% block page_main %}
    <h2 class="sub-header">修改生产信息</h2>
    <form action="" method="post" novalidate>
        {% csrf_token %}
        {% for field in form_obj %}
            {% if field.label in disabled_list %}
                <div class="form-group {% if field.errors.0 %}has-error {% endif %} disabled">
                    <label for="{{ field.id_for_label }}"
                           class="col-sm-2 control-label disabled">{{ field.label }}</label>
                    {{ field }}
                    <span class="help-block">{{ field.errors.0 }}</span>
                </div>
            {% else %}
                <div class="form-group {% if field.errors.0 %}has-error {% endif %}">
                    <label for="{{ field.id_for_label }}" class="col-sm-2 control-label">{{ field.label }}</label>
                    {{ field }}
                    <span class="help-block">{{ field.errors.0 }}</span>
                </div>
            {% endif %}

        {% endfor %}
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="submit" class="btn btn-success">
            </div>
            <div id="plan_id" hidden>{{ plan_id }}</div>
        </div>

    </form>
{% endblock %}

{% block js %}
    <script>
        //机种名不能修改设置
        var $skuEle = $('#id_plan_pro_code')
        {#var $val1 = $skuEle.val()#}
        {#console.log($val1)#}
        $skuEle.attr('readonly', 'ture')
        $skuEle.attr('onfocus', 'this.defaultIndex=this.selectedIndex;')
        $skuEle.attr('onchange', 'this.selectedIndex=this.defaultIndex;')

        //计划id不能修改设置
        var $planEle = $('#id_sku')
        $planEle.attr('readonly', 'ture')
        $planEle.attr('onfocus', 'this.defaultIndex=this.selectedIndex;')
        $planEle.attr('onchange', 'this.selectedIndex=this.defaultIndex;')

        //订单id不能修改设置
        var $orderEle = $('#id_Lot')
        $orderEle.attr('readonly', 'ture')
        $orderEle.attr('onfocus', 'this.defaultIndex=this.selectedIndex;')
        $orderEle.attr('onchange', 'this.selectedIndex=this.defaultIndex;')


        let $planId = $('#plan_id').text()

        // let url = window.location.href; /* 获取完整URL */
        function foo() {
            $.ajax({
                url: '/plan/ajax_calculate/',
                type: 'get',
                data: {
                    'plan_id': $planId
                },
                //请求成功接受结果
                success: function (back_dic) {
                    let cap = parseInt(back_dic.cap)
                    let sku_num = $("#id_work_int").val()
                    let work_hours = sku_num / cap * 10.5  //生产时间
                    let hours = work_hours.toFixed(4)
                    let inputEle = $("#id_working_hours").attr("value", hours)
                    console.log(inputEle)
                }
            })
        }

        foo()
        $(document).ready(function () {
            $("#id_work_int").on("change", function () {
                foo()
            })
        })

    </script>


{% endblock %}

{#{% block js %}#}
{##}
{#    <script>#}
{#    $(document).ready(function (){#}
{#        $('#id_customer').on('change',function (){#}
{#            // 获取到选中的校区id#}
{#            var customer_id = $(this).val();#}
{#            // 发送ajax请求到后端取出当前校区下面的所有课程#}
{#            $.ajax({#}
{#                url:'/plan/ajax_customer/',#}
{#                type:'get',#}
{#                data:{#}
{#                    'customer_id':customer_id#}
{#                },#}
{#                //请求成功接受结果#}
{#                success:function (res){#}
{#                    console.log(res);#}
{#                    // 找到id_sku 这个标签  机种选择的输入框#}
{#                    var $classSelect = $('#id_sku');#}
{#                    // 给原来的数据置空，删除以前的数据#}
{#                    $classSelect.text('');#}
{#                    //添加 默认的 optione html代码  <option value="">-------</option>#}
{#                    $classSelect.append('<option value="">-------</option>');#}
{#                    //循环后端返回的数据#}
{#                    $.each(res.data,function (k,v){#}
{#                        console.log(k,v);#}
{#                        //声明option标签#}
{#                        var opEle = document.createElement('option');#}
{#                        // 给后端返回的数据添加到标签中#}
{#                        $(opEle).text(v.name).attr('value',v.id)#}
{#                        //数据添加到选课框中#}
{#                        $classSelect.append(opEle)#}
{##}
{#                    })#}
{#                }#}
{#            })#}
{#        })#}
{#    })#}
{#    </script>#}
{##}
{#{% endblock %}#}


<form>
    <div class="row">
        <div class="col"><label class="form-inline">名： <input type="text" class="form-control"
                                                               placeholder="First name"> </label></div>
        <div class="col"><label class="form-inline">姓： <input type="text" class="form-control" placeholder="Last name">
        </label></div>
    </div>
</form>
